#ifndef CCUISINEMODEL_H
#define CCUISINEMODEL_H

#include <QObject>
//#include <QtSql>
//#include <QSqlRelationalTableModel>
#include <QSqlTableModel>
#include "cconstdefinition.h"
#include "cmodel.h"
//#include "cobject.h"
namespace cooking {

/**
 * Cuisine model, used by UI to query cuisine list by region
 */
class CCuisineModel : public CModel
{
    Q_OBJECT
    Q_PROPERTY(int parentId READ parentId WRITE setParentId NOTIFY parentIdChanged)

public:
    explicit CCuisineModel(CEngine& engine, QObject *parent = 0);
    CCuisineModel(int parentId, CEngine& engine, QObject *parent = 0);
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    /**
     * Get data by index and role
     */
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

    /**
     * Set the parent cuisine id of this model, this may change the data
     * @param parentId parent cuisine id
     */
    void setParentId(int parentId);

    /**
     * Get the parent cuisine id of this model
     * @return parent cuisine id
     */
    int parentId();

signals:
    void parentIdChanged();

public slots:

protected:
    QString queryString();
    void refresh();
    void initRoles();

private:
    int getSelectCuisineId(const QModelIndex& index) const;
    void childrenCuisineIds(int parentId, QList<int>& childrenIds, bool recursive) const;
    void directChildrenIds(int parentId, QList<int>& childrenIds) const;

private:
    const static QString KCuisineRoleNamesMap[][2];
    int m_parentId;
    int m_roleStart;
    int m_roleEnd;
};
} // namespace cooking
#endif // CCUISINEMODEL_H
